window.onload = function () {
},
    $(function () {
        Designer.init(),
            UI.init(),
            Designer.loadStation()
    });
var Designer = {
        config: {
            panelItemWidth: 30,
            panelItemHeight: 30,
            pageMargin: 1e3,
            scale: 1,
            movePosPix: 2,
            moveSmallPosPix: .5
        },
        shapes: [],
        initialize: {
            initialized: !1,
            initlayout: function () {
                $(window).bind("resize.designer",
                    function () {
                        var e = $(window).height() - $("#designer_header").outerHeight() - $("#designer_footer").outerHeight();
                        $(".layout").height(e),
                            $("#designer_layout").height(e)
                    }),
                    $(window).trigger("resize.designer")
            },
            constructMetaShapes: function () {
                function e() {
                    var e = Designer.shapes,
                        t = metaShape.switchObj;
                    t.createObj("switchsdx", "道岔-定位", "SHUN_XIANG", 0, "DING_WEI", 0, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.switchObj,
                        t.createObj("switchfds", "道岔-定位", "FAN_XIANG", 180, "DING_WEI", 30, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.switchObj,
                        t.createObj("switchsds", "道岔-定位", "SHUN_XIANG", 180, "DING_WEI", 30, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t);
                    var t = metaShape.switchObj;
                    t.createObj("switchfdx", "道岔-定位", "FAN_XIANG", 0, "DING_WEI", 0, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t);
                    var t = metaShape.switchObj;
                    t.createObj("switchsfx_x", "道岔-反位", "SHUN_XIANG", 45, "FAN_WEI", 0, 0),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.switchObj,
                        t.createObj("switchffs_x", "道岔-反位", "FAN_XIANG", 135, "FAN_WEI", 23, 2.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.switchObj,
                        t.createObj("switchsfs_x", "道岔-反位", "SHUN_XIANG", 225, "FAN_WEI", 22, 27),
                        t = $.extend(!0, {},
                            t),
                        e.push(t);
                    var t = metaShape.switchObj;
                    t.createObj("switchffx_x", "道岔-反位", "FAN_XIANG", 315, "FAN_WEI", 1, 26),
                        t = $.extend(!0, {},
                            t),
                        e.push(t);
                    var t = metaShape.switchObj;
                    t.createObj("switchsfx", "道岔-反位", "SHUN_XIANG", 0, "FAN_WEI", 0, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.switchObj,
                        t.createObj("switchffs", "道岔-反位", "FAN_XIANG", 180, "FAN_WEI", 30, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.switchObj,
                        t.createObj("switchsfs", "道岔-反位", "SHUN_XIANG", 180, "FAN_WEI", 30, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t);
                    var t = metaShape.switchObj;
                    t.createObj("switchffx", "道岔-反位", "FAN_XIANG", 0, "FAN_WEI", 0, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t);
                    var t = metaShape.switchObj;
                    t.createObj("switchsdx_x", "道岔-定位", "SHUN_XIANG", 45, "DING_WEI", 4, 2),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.switchObj,
                        t.createObj("switchfds_x", "道岔-定位", "FAN_XIANG", 135, "DING_WEI", 26, 5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.switchObj,
                        t.createObj("switchsds_x", "道岔-定位", "SHUN_XIANG", 225, "DING_WEI", 25.5, 28),
                        t = $.extend(!0, {},
                            t),
                        e.push(t);
                    var t = metaShape.switchObj;
                    t.createObj("switchfdx_x", "道岔-定位", "FAN_XIANG", 315, "DING_WEI", 6, 27),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function t() {
                    var e = Designer.shapes,
                        t = metaShape.metaSignal;
                    t.createObj("lie_a", "列车矮柱", "LIE_A", 0, 3.5, 8.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.metaSignal,
                        t.createObj("lie_af", "列车矮柱", "LIE_A", 180, 4.5, 8.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.metaSignal,
                        t.createObj("lie_g", "列车高柱", "LIE_G", 0, 1, 8.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.metaSignal,
                        t.createObj("lie_gf", "列车高柱", "LIE_G", 180, -23.5, 8.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.metaSignal,
                        t.createObj("diao_a", "调车矮柱", "DIAO_A", 0, 10.5, 8.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.metaSignal,
                        t.createObj("diao_af", "调车矮柱", "DIAO_A", 180, -3, 8.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.metaSignal,
                        t.createObj("diao_g", "调车高柱", "DIAO_G", 0, 5.5, 8.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.metaSignal,
                        t.createObj("diao_gf", "调车高柱", "DIAO_G", 180, -9.5, 8.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function n() {
                    var e = Designer.shapes,
                        t = metaShape.metaTrack;
                    t.createObj("track", "区段", "WG", "TRACK", 0, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function i() {
                    var e = Designer.shapes,
                        t = metaShape.metaLianXi;
                    t.createObj("zhaocha", "照查", "ZHAO_CHA", 15, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function o() {
                    var e = Designer.shapes,
                        t = metaShape.metaTuoGuiQi;
                    t.createObj("tuoguiqi", "脱轨器", "TUO_GUI_QI", 4.5, 25.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function a() {
                    var e = Designer.shapes,
                        t = metaShape.metaQinXian;
                    t.createObj("qinxian", "侵线绝缘", "QIN_XIAN", 15, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function s() {
                    var e = Designer.shapes,
                        t = metaShape.metaStubEndSinding;
                    t.createObj("stubEndSindingS", "尽头线", "STUB_END_SIDING", 0, 2.5, 8.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.metaStubEndSinding,
                        t.createObj("stubEndSindingF", "尽头线", "STUB_END_SIDING", 180, -30.5, 8.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function r() {
                    var e = Designer.shapes,
                        t = metaShape.meta64D;
                    t.createObj("64ds", "半自动闭塞", "64D", 0, 8, 12.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.meta64D,
                        t.createObj("64df", "半自动闭塞", "64D", 180, 26, 12.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function h() {
                    var e = Designer.shapes,
                        t = metaShape.metaJYJ;
                    t.createObj("JYJH", "绝缘节", "JYJ", 0, 13.5, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t),
                        t = metaShape.metaJYJ,
                        t.createObj("JYJV", "绝缘节", "JYJ", 90, 14.5, 13.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function l() {
                    var e = Designer.shapes,
                        t = metaShape.metaButton;
                    t.createObj("button", "按钮", "BUTTON", 6, 4.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function c() {
                    var e = Designer.shapes,
                        t = metaShape.metaTrack;
                    t.createObj("", "辅助线段", "LINE", "LINE", 0, 14.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function p() {
                    var e = Designer.shapes,
                        t = metaShape.metaTextShap;
                    t.createObj("text", "文字", "TEXT", 6, 6.5),
                        t = $.extend(!0, {},
                            t),
                        e.push(t)
                }

                function f() {
                }

                function d() {
                }

                e(),
                    n(),
                    t(),
                    i(),
                    o(),
                    d(),
                    c(),
                    f(),
                    p(),
                    a(),
                    s(),
                    r(),
                    l(),
                    h()
            },
            initCanvas: function () {
                Model.page.width = Model.page.width.toScale(),
                    Model.page.height = Model.page.height.toScale(),
                    Model.page.padding = Model.page.padding.toScale();
                var e = Model.page.width,
                    t = Model.page.height,
                    n = Model.page.padding,
                    o = (Model.page.backgroundColor, "242,242,242"),
                    s = e + 2 * n,
                    r = t + 2 * n;
                $("#canvas_container_border").css({
                    width: s + 2 * n + "px",
                    height: r + 2 * n + "px",
                    "background-color": "rgb(" + o + ")",
                    padding: n + "px"
                }),
                    $("#designer_canvas").css({
                        width: s,
                        height: r,
                        "background-color": "rgb(" + o + ")"
                    });
                var h = $("#designer_grids");
                h.attr({
                    width: s,
                    height: r
                }),
                    s += 2 * Designer.config.pageMargin.toScale(),
                    r += 2 * Designer.config.pageMargin.toScale(),
                    $("#canvas_container").css({
                        width: s,
                        height: r,
                        padding: Designer.config.pageMargin.toScale()
                    }),
                this.initialized || ($("#designer_layout").scrollTop(Designer.config.pageMargin - 10), $("#designer_layout").scrollLeft(Designer.config.pageMargin - 10))
            },
            initShapePanel: function () {
                function n(e) {
                    var n, i, t = e.category;
                    switch (t) {
                        case "SWITCH":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_switch");
                            break;
                        case "TRACK":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_other");
                            break;
                        case "SIGNAL":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_signal");
                            break;
                        case "LIANXI":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_other");
                            break;
                        case "TUO_GUI_QI":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_other");
                            break;
                        case "QIN_XIAN":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_other");
                            break;
                        case "STUB_END_SIDING":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_other");
                            break;
                        case "64D":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_other");
                            break;
                        case "JYJ":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_other");
                            break;
                        case "BUTTON":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_other");
                            break;
                        case "LINE":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_assit");
                            break;
                        case "TEXT":
                            n = "<div class='panel_box' shapeName='" + e.name + "'><canvas class='panel_item' width='" + Designer.config.panelItemWidth + "'height='" + Designer.config.panelItemHeight + "'></canvas></div>",
                                i = $(n).appendTo("#panel_assit")
                    }
                    i.bind("mouseenter",
                        function () {
                            var t = 110 / Designer.config.panelItemWidth,
                                n = 110 / Designer.config.panelItemHeight,
                                i = $("#shape_thumb");
                            i.children("div").text(e.nameText);
                            var o = i.children("canvas")[0],
                                a = o.getContext("2d");
                            a.clearRect(0, 0, 160, 160),
                                i.children("canvas").attr({
                                    width: 160,
                                    height: 130
                                }),
                                i.show(),
                                a.save(),
                                a.translate(20, 20),
                                a.scale(t, n),
                                e.displayMetaShape(o, 100, 100),
                                a.restore()
                        }).bind("mouseleave",
                        function () {
                            $("#shape_thumb").hide()
                        }),
                        e.displayMetaShape(i.children()[0], Designer.config.panelItemWidth, Designer.config.panelItemHeight)
                }

                function i() {
                    function e(e) {
                        var t = $("#creating_shape_canvas"),
                            n = $("#creating_shape_container");
                        0 == t.length && (n = $("<div id='creating_shape_container'></div>").appendTo("#designer"), t = $("<canvas id='creating_shape_canvas' width='" + Designer.config.panelItemWidth + "' height='" + Designer.config.panelItemHeight + "'></canvas>").appendTo(n)),
                            n.css({
                                left: "0px",
                                top: "0px",
                                width: $(".panel_container").width(),
                                height: $("#shape_panel").outerHeight()
                            });
                        var i = n.children("canvas")[0].getContext("2d");
                        return i.clearRect(0, 0, Designer.config.panelItemWidth, Designer.config.panelItemHeight),
                            Designer.shapes[e].displayMetaShape(n.children("canvas")[0], Designer.config.panelItemWidth, Designer.config.panelItemHeight),
                            t
                    }

                    function t(e) {
                        var t;
                        for (t = 0; t < Designer.shapes.length; t++) if (Designer.shapes[t].name == e) return t
                    }

                    function n(e, t) {
                        $("#creating_shape_container").show();
                        var n = Utils.getRelativePos(t.pageX, t.pageY, $("#creating_shape_container"));
                        e.css({
                            left: n.x - Designer.config.panelItemWidth / 2,
                            top: n.y - Designer.config.panelItemHeight / 2
                        })
                    }

                    function i(e, t, n) {
                        var i = Utils.newId(),
                            o = Utils.copy(Designer.shapes[e]);
                        return o.id = i,
                            o.setBasicPara(),
                            o.MoveOffset(t, n),
                            o.renderShape(Designer.op.zoomCount),
                            o
                    }

                    $(".panel_box").die().live("mousedown",
                        function () {
                            var o = $(this),
                                a = t(o.attr("shapename")),
                                s = e(a);
                            $("#designer").bind("mousemove.creating",
                                function (e) {
                                    n(s, e)
                                });
                            var r = $("#designer_canvas"),
                                h = null,
                                l = !1,
                                c = -1;
                            $("#canvas_container").bind("mousemove.create",
                                function (e) {
                                    var t = Utils.getRelativePos(e.pageX, e.pageY, r);
                                    l = !1,
                                    null == h && (h = i(a, t.x, t.y), h.offsetPre = {
                                        x: t.x,
                                        y: t.y
                                    },
                                        l = !0, Model.elements.push(h), c = Model.elements.length - 1),
                                        e.preventDefault(),
                                        Designer.MoveItem(r.children("canvas")[0], h, t.x - h.offsetPre.x, t.y - h.offsetPre.y),
                                        h.offsetPre = t
                                });
                            var p = !1;
                            $("#canvas_container").bind("mouseup.creat",
                                function (e) {
                                    p = !0
                                }),
                                $(document).bind("mouseup.create",
                                    function () {
                                        $(this).unbind("mouseup.create"),
                                            $("#designer").unbind("mousemove.creating"),
                                            $("#creating_shape_container").hide(),
                                            $("#canvas_container").unbind("mouseup.create").unbind("mousemove.create"),
                                        !p && l && (Model.elements.pop(), Designer.DisplayElements(r.children("canvas")[0]))
                                    })
                        })
                }

                $("#shape_panel").empty(),
                    $("#shape_panel").append("<div class='panel_container'><h3 class='panel_title'><div class='ico ico_accordion'></div>道岔类型</h3><div id=panel_switch class='content'></div></div>"),
                    $("#shape_panel").append("<div class='panel_container'><h3 class='panel_title'><div class='ico ico_accordion'></div>信号机类型</h3><div id=panel_signal class='content'></div></div>"),
                    $("#shape_panel").append(" <div class='panel_container'><h3 class='panel_title'><div class='ico ico_accordion'></div>其它设备</h3><div id=panel_other class='content'></div></div>"),
                    $("#shape_panel").append("<div class='panel_container'><h3 class='panel_title'><div class='ico ico_accordion'></div>辅助工具</h3><div id=panel_assit class='content'></div></div>"),
                    $(".panel_title").unbind().bind("click",
                        function () {
                            $(this).parent().toggleClass("panel_collapsed")
                        });
                for (var e = 0; e < Designer.shapes.length; e++) {
                    var t = Designer.shapes[e];
                    n(t)
                }
                i()
            }
        },
        init: function () {
            this.initialize.initlayout(),
                this.initialize.initCanvas(),
                this.initialize.constructMetaShapes(),
                this.initialize.initShapePanel(),
                this.op.init(),
                this.hotkey.init(),
                $("#btn_back").unbind("click").bind("click",
                    function () {
                        Designer.initialize.initialized = !1
                    })
        },
        stationID: null,
        loadStation: function () {
            function o() {
                var e = localStorage.getItem("currentStation");
                if (e = JSON.parse(e)) {
                    if (Model.fileInfo = [], Model.elements = [], Model.fhSwitchTable = [], Model.ddSwitchTable = [], Model.fileInfo = e[0], this.element = e[1], this.element) for (var t = 0; t < this.element.length; t++) Model.initObj(this.element[t]);
                    e[2] ? Model.fhSwitchTable = e[2] : Model.fhSwitchTable = [],
                        e[3] ? Model.ddSwitchTable = e[3] : Model.ddSwitchTable = [],
                        e[4] ? lsb.routateTable = e[4] : lsb.routateTable = [],
                        e[5] ? lsb.lsbStringData = e[5] : lsb.lsbStringData = [],
                        Designer.op.refreshElements()
                }
            }

            var e = document.location.href,
                t = "";
            if ("?" == e.match("\\u003F") && (t = decodeURI(e.split("?")[1].split("=")[1])), "" == t || !t) return void o();
            "#" == t[t.length - 1] && (t = t.substring(0, t.length - 1)),
                Designer.stationID = t;
            var n = $(window).height(),
                i = $(window).width();
            showLoadingGif(80, $("#loading_wait"), !0, {
                x: n / 2,
                y: i / 10
            }),
                Designer.getStationData(t,
                    function (e, t) {
                        return showLoadingGif(80, $("#loading_wait"), !1),
                            e ? void showAlertInfo("系统繁忙，请稍后再试！") : void(t && Designer.initStationData(t))
                    })
        },
        getStationData: function (e, t) {
            $.ajax({
                url: "getSharedStationData",
                data: {
                    stationID: e
                },
                type: "post",
                cache: !1,
                dataType: "json",
                success: function (e) {
                    e || 501 !== e ? t(null, e) : t("data error", null)
                },
                error: function () {
                    return document.location.href = encodeURI("./errorpage")
                }
            })
        },
        initStationData: function (e) {
            if (e) {
                if (Model.elements = [], Model.fhSwitchTable = [], Model.ddSwitchTable = [], e.elements) for (var t = 0; t < e.elements.length; t++) Model.initObj(e.elements[t]);
                e.ffswitch ? Model.fhSwitchTable = e.ffswitch : Model.fhSwitchTable = [],
                    e.ddswitch ? Model.ddSwitchTable = e.ddswitch : Model.ddSwitchTable = [],
                    e.routeTable ? lsb.routateTable = e.routeTable : lsb.routateTable = [],
                    e.lktable ? lsb.lsbStringData = e.lktable : lsb.lsbStringData = [],
                    Designer.op.refreshElements(),
                    $("#diagram_title").text(e.title),
                    Designer.initialize.initialized = !0
            }
        },
        user: "default",
        op: {
            currentSelectedID: -1,
            currentSelectedGroupID: [],
            copyShapeIndex: -1,
            zoomCount: 1,
            tipInfo: !1,
            jyjShowFlag: !0,
            buttonShowFlag: !0,
            init: function () {
                function g(t, n) {
                    function h(e) {
                        return s.beginPath(),
                            s.rect(o[0], o[1], o[2] - o[0], o[3] - o[1]),
                            s.isPointInPath(e.x, e.y) ? !0 : !1
                    }

                    for (var i = Model.elements,
                             o = [t.x, t.y, n.x, n.y], a = $("#designer_grids"), s = a[0].getContext("2d"), r = 0; r < i.length; r++)"SWITCH" == i[r].category ? (h(i[r].component.chaJian[0]) || h(i[r].component.chaZhi[1]) || h(i[r].component.chaWan[1])) && (Designer.op.currentSelectedGroupID.push(r), Designer.op.setSelectedStatu(!0, r)) : "SIGNAL" == i[r].category ? (h(i[r].component.base[0]) || h(i[r].component.base[1])) && (Designer.op.currentSelectedGroupID.push(r), Designer.op.setSelectedStatu(!0, r)) : "TRACK" == i[r].category ? (h(i[r].component.point[0]) || h(i[r].component.point[1])) && (Designer.op.currentSelectedGroupID.push(r), Designer.op.setSelectedStatu(!0, r)) : "LIANXI" == i[r].category ? h(i[r].component.point[0]) && (Designer.op.currentSelectedGroupID.push(r), Designer.op.setSelectedStatu(!0, r)) : "TUO_GUI_QI" == i[r].category ? h(i[r].component.point[0]) && (Designer.op.currentSelectedGroupID.push(r), Designer.op.setSelectedStatu(!0, r)) : "QIN_XIAN" == i[r].category ? h(i[r].component.point[0]) && (Designer.op.currentSelectedGroupID.push(r), Designer.op.setSelectedStatu(!0, r)) : "STUB_END_SIDING" == i[r].category ? (h(i[r].component.point[0]) || h(i[r].component.point[1])) && (Designer.op.currentSelectedGroupID.push(r), Designer.op.setSelectedStatu(!0, r)) : "64D" == i[r].category ? (h(i[r].component.point[0]) || h(i[r].component.point[6])) && (Designer.op.currentSelectedGroupID.push(r), Designer.op.setSelectedStatu(!0, r)) : "BUTTON" == i[r].category ? h(i[r].component.point[0]) && (Designer.op.currentSelectedGroupID.push(r), Designer.op.setSelectedStatu(!0, r)) : "TEXT" == i[r].category && h(i[r].component.point[0]) && (Designer.op.currentSelectedGroupID.push(r), Designer.op.setSelectedStatu(!0, r));
                    Designer.DisplayElements(e.children("canvas")[0]),
                        s.save(),
                        s.beginPath(),
                        s.rect(o[0], o[1], o[2] - o[0], o[3] - o[1]),
                        s.stroke(),
                        s.restore()
                }

                var r, e = $("#designer_canvas"),
                    t = $("#canvas_container"),
                    i = -1,
                    o = !1,
                    a = !1,
                    s = !1,
                    h = !1,
                    l = 0,
                    c = !1,
                    p = !1,
                    d = null;
                e.bind("mousedown",
                    function (n) {
                        var r = Utils.getRelativePos(n.pageX, n.pageY, e);
                        if (n.preventDefault(), -1 == i) -1 != Designer.op.currentSelectedID && (Designer.op.currentSelectedID = -1, Designer.op.setSelectedStatu(!1, -1), Designer.DisplayElements(e.children("canvas")[0])),
                            c = !0,
                            d = r,
                        Designer.op.currentSelectedGroupID.length > 0 && (Designer.op.currentSelectedGroupID.splice(0, Designer.op.currentSelectedGroupID.length), Designer.op.setSelectedStatu(!1, -1), Designer.DisplayElements(e.children("canvas")[0]), i = -1);
                        else if (Designer.op.currentSelectedID != i) {
                            Designer.op.currentSelectedID = i;
                            for (var h = !1,
                                     l = 0; l < Designer.op.currentSelectedGroupID.length; l++) if (Designer.op.currentSelectedGroupID[l] == i) {
                                h = !0;
                                break
                            }
                            h || (Designer.op.setSelectedStatu(!1, -1), Designer.op.setSelectedStatu(!0, i), Designer.op.currentSelectedGroupID.length > 0 && Designer.op.currentSelectedGroupID.splice(0, Designer.op.currentSelectedGroupID.length)),
                                Designer.DisplayElements(e.children("canvas")[0])
                        }
                        Designer.op.cursonInRotatePoint(i, r) ? (s = !0, t.css("cursor", "pointer")) : Designer.op.cursonInControlPoint(i, r) ? (a = !0, Designer.op.setControlPoint(i, r), t.css("cursor", "pointer")) : Designer.op.cursonInShape(i, r) && (o = !0, t.css("cursor", "move"))
                    }),
                    e.bind("mousemove",
                        function (e) {
                            var n = $("#designer_canvas"),
                                l = Utils.getRelativePos(e.pageX, e.pageY, n);
                            e.preventDefault(),
                                p = !0,
                                o ? (Designer.op.draggingShape(i, l.x - r.x, l.y - r.y), r = l) : a ? (Designer.op.controlShape(i, l), r = l) : s ? (Designer.op.rotateShape(i, l), r = l) : (p = !1, i = Designer.op.getShapeByPos(l), r = l, -1 != i ? (Designer.op.displayStatu(i, "selected"), Designer.op.cursonInControlPoint(i, l) ? t.css("cursor", "pointer") : Designer.op.cursonInRotatePoint(i, l) ? t.css("cursor", "pointer") : t.css("cursor", "move"), h = !0, Designer.op.tipInfo && UI.showShapeTipInfo(i, e)) : (h && (t.css("cursor", "default"), Designer.DisplayElements(n.children("canvas")[0]), h = !1, UI.showShapeTipInfo(-1, e)), d && (Designer.op.currentSelectedGroupID.length > 0 && (Designer.op.currentSelectedGroupID.splice(0, Designer.op.currentSelectedGroupID.length), Designer.op.setSelectedStatu(!1, -1)), g(d, l))))
                        }),
                    e.bind("mouseup",
                        function (n) {
                            if (o = !1, a = !1, s = !1, l = 0, c = !1, d = null, t.css("cursor", "default"), p && (p = !1), Designer.op.currentSelectedGroupID.length > 0 && Designer.DisplayElements(e.children("canvas")[0]), Designer.op.currentSelectedGroupID.length > 0) for (var r = [], h = 0; h < Designer.op.currentSelectedGroupID.length; h++) r.push({
                                index: Designer.op.currentSelectedGroupID[h],
                                ele: Model.elements[Designer.op.currentSelectedGroupID[h]]
                            })
                        })
            },
            refreshElements: function (e) {
                var t = $("#designer_canvas");
                Designer.DisplayElements(t.children("canvas")[0])
            },
            setOpMode: function (e) {
                var t = $("#designer_canvas");
                if ("PATH_REVIEW_Mode" == e) $("#designer_canvas").unbind("mousedown").unbind("mousemove").unbind("mouseup").bind("mousemove.lsbreview",
                    function (e) {
                        var n = Utils.getRelativePos(e.pageX, e.pageY, t);
                        e.preventDefault();
                        var i = Designer.op.getShapeByPos(n),
                            o = $("#canvas_container");
                        -1 != i ? (o.css("cursor", "pointer"), lsb.setPathObjStatu(i, "SELECTED_P")) : (o.css("cursor", "default"), lsb.setPathObjStatu(-1, "DEFAULT")),
                            Designer.DisplayElements(t.children("canvas")[0])
                    });
                else if ("CFGSMode" == e) {
                    var n = -1,
                        i = [],
                        o = !1;
                    $("#designer_canvas").unbind("mousedown").unbind("mousemove").unbind("mouseup").bind("mousedown.cds",
                        function (e) {
                            var t = $("#designer_canvas"),
                                a = Utils.getRelativePos(e.pageX, e.pageY, t);
                            e.preventDefault();
                            var s = Designer.op.getShapeByPos(a);
                            if (Model.dsExisted(s));
                            else if (-1 != s) {
                                if (o) {
                                    for (var r = !1,
                                             h = 0; h < i.length; h++) {
                                        if (Model.getIDByIndex(s) == i[h]) {
                                            Model.elements[s].otherSwitch = Model.getIDByIndex(n),
                                                Model.elements[n].otherSwitch = Model.getIDByIndex(s),
                                                Designer.op.setShowStatu(Model.getIndexByID(i[h]), "SELECTEDDS"),
                                                Designer.op.setShowStatu(n, "SELECTEDDS");
                                            for (var l = 0; l < i.length; l++) l != h && Designer.op.setShowStatu(Model.getIndexByID(i[l]), "DEFAULT");
                                            r = !0;
                                            var c = {
                                                x: 0,
                                                y: 0
                                            };
                                            c.x = e.pageX,
                                                c.y = e.pageY,
                                                UI.showFloatTipMessage(Model.elements[s].name + " 与 " + Model.elements[n].name + "为双动道岔,若判断错误请双击取消", c);
                                            break
                                        }
                                        Designer.op.setShowStatu(s, "DEFAULT")
                                    }
                                    if (!r) {
                                        Designer.op.setShowStatu(n, "DEFAULT");
                                        for (var h = 0; h < i.length; h++) Designer.op.setShowStatu(Model.getIndexByID(i[h]), "DEFAULT")
                                    }
                                    o = !1,
                                        n = -1,
                                        i = -1,
                                        Designer.DisplayElements(t.children("canvas")[0])
                                } else if (!Model.dsExisted(s)) {
                                    n = s,
                                        o = !0,
                                        i = Designer.op.findOther(n),
                                        Designer.op.setShowStatu(n, "ONE");
                                    for (var h = 0; h < i.length; h++) Designer.op.setShowStatu(Model.getIndexByID(i[h]), "OTHER");
                                    Designer.DisplayElements(t.children("canvas")[0])
                                }
                            } else {
                                Designer.op.setShowStatu(n, "DEFAULT");
                                for (var h = 0; h < i.length; h++) Designer.op.setShowStatu(Model.getIndexByID(i[h]), "DEFAULT");
                                o = !1,
                                    n = -1,
                                    i = -1,
                                    Designer.DisplayElements(t.children("canvas")[0])
                            }
                        }).bind("mousemove.cds",
                        function (e) {
                            var n = Utils.getRelativePos(e.pageX, e.pageY, t);
                            e.preventDefault();
                            var i = Designer.op.getShapeByPos(n),
                                o = $("#canvas_container");
                            -1 != i ? o.css("cursor", "pointer") : o.css("cursor", "default")
                        }).bind("dblclick.cds",
                        function (e) {
                            var n = Utils.getRelativePos(e.pageX, e.pageY, t);
                            e.preventDefault();
                            var i = Designer.op.getShapeByPos(n);
                            -1 != i && Model.dsExisted(i) && (Model.cancelDSSelected(i), Designer.DisplayElements(t.children("canvas")[0]))
                        })
                } else "OPMode" == e && (t.unbind("mousedown.cds").unbind("mousemove.cds").unbind("dblclick.cds").unbind("mousemove.lsbreview"), Designer.op.init(), Model.setDefalutStatu(), Designer.DisplayElements(t.children("canvas")[0]))
            },
            findOther: function (e) {
                return Model.findOther(e, $("#designer_canvas").children("canvas")[0])
            },
            setShowStatu: function (e, t) {
                Model.setShowStatu(e, t)
            },
            getCurrentSelectedID: function () {
                return Designer.op.currentSelectedID
            },
            cursonInControlPoint: function (e, t) {
                var n = $("#designer_canvas");
                return -1 == e ? !1 : Model.elements[e].inControlPoint(n.children("canvas")[0], t)
            },
            cursonInRotatePoint: function (e, t) {
                var n = $("#designer_canvas");
                return -1 == e ? !1 : Model.elements[e].inRotatePoint(n.children("canvas")[0], t)
            },
            cursonInShape: function (e, t) {
                var n = $("#designer_canvas");
                return -1 == e ? !1 : Model.elements[e].inShape(n.children("canvas")[0], t)
            },
            draggingShape: function (e, t, n) {
                function a(n, i, o, a, s) {
                    return Math.abs(i.y + a - s.y) < 3 ? (Model.elements[e].MoveOffset(t, s.y - i.y), Math.abs(i.x + o - s.x) < 3 && Model.elements[e].MoveOffset(s.x - i.x + 1, 0), !0) : !1
                }

                function s(e, t, n) {
                    return Math.abs(e.x - t.x) < Math.abs(e.x - n.x) ? t : n
                }

                function r(e, t) {
                    for (var n = 0; n < Model.elements.length; n++) if (Model.elements[n].id !== t.id) if ("TRACK" !== Model.elements[n].category) {
                        if ("SWITCH" !== Model.elements[n].category);
                        else if (Model.elements[n].component.chaJian[0].y === Model.elements[n].component.chaZhi[1].y) {
                            if (Utils.inPoint(i.children("canvas")[0], e, Model.elements[n].component.chaJian[0])) return Model.elements[n];
                            if (Utils.inPoint(i.children("canvas")[0], e, Model.elements[n].component.chaZhi[1])) return Model.elements[n];
                            continue
                        }
                    } else {
                        if (Model.elements[n].component.point[0].y !== Model.elements[n].component.point[1].y) continue;
                        if (Utils.inPoint(i.children("canvas")[0], e, Model.elements[n].component.point[0])) return Model.elements[n];
                        if (Utils.inPoint(i.children("canvas")[0], e, Model.elements[n].component.point[1])) return Model.elements[n]
                    }
                    return -1
                }

                function h(e, t, n) {
                    if ("TRACK" === e.category) {
                        if (e.component.point[0].y === e.component.point[1].y) {
                            var i = -1;
                            i = e.component.point[0].x <= e.component.point[1].x ? e.component.point[0] : e.component.point[1];
                            var o = r(i, e);
                            if (-1 === o) return !1;
                            if ("TRACK" !== o.category) return "SWITCH" === o.category && a(e, i, t, n, s(i, o.component.chaJian[0], o.component.chaZhi[1])) ? !0 : !1;
                            if (o.component.point[0].y === o.component.point[1].y) return a(e, i, t, n, s(i, o.component.point[0], o.component.point[1])) ? !0 : !1
                        }
                    } else if ("SWITCH" === e.category && e.component.chaJian[0].y === e.component.chaZhi[1].y) {
                        var i = -1;
                        i = e.component.chaJian[0].x <= e.component.chaZhi[1].x ? e.component.chaJian[0] : e.component.chaZhi[1];
                        var o = r(i, e);
                        if (-1 === o) return !1;
                        if ("TRACK" !== o.category) return "SWITCH" === o.category && a(e, i, t, n, s(i, o.component.chaJian[0], o.component.chaZhi[1])) ? !0 : !1;
                        if (o.component.point[0].y === o.component.point[1].y) return a(e, i, t, n, s(i, o.component.point[0], o.component.point[1])) ? !0 : !1
                    }
                    return !1
                }

                var i = $("#designer_canvas");
                if (-1 == e) return !1;
                if (Designer.op.currentSelectedGroupID.length > 0) for (var o = 0; o < Designer.op.currentSelectedGroupID.length; o++) Model.moveShape(Designer.op.currentSelectedGroupID[o], t, n);
                else h(Model.elements[e], t, n) || Model.elements[e].MoveOffset(t, n);
                Designer.DisplayElements(i.children("canvas")[0]),
                    Designer.op.displayStatu(e, "selected")
            },
            controlShape: function (e, t) {
                var n = $("#designer_canvas");
                return -1 == e ? !1 : (Model.elements[e].scratchShape(n.children("canvas")[0], t), Designer.DisplayElements(n.children("canvas")[0]), void Designer.op.displayStatu(e, "selected"))
            },
            changChaWanAngel: function (e, t) {
                var n = $("#designer_canvas");
                return -1 == e ? !1 : (Model.elements[e].changeChaWanAngel(e, t), void Designer.DisplayElements(n.children("canvas")[0]))
            },
            rotateShape: function (e, t) {
                var n = $("#designer_canvas");
                if (-1 == e) return !1;
                var i = Model.elements[e].getRotateCoordinatePoint();
                if (t.x - i.x != 0) {
                    var o, a, s, r;
                    o = Math.atan((t.y - i.y) / (t.x - i.x)),
                        Math.abs(180 * o / Math.PI) > 70 ? (Model.elements[e].calcuRotateAngel(45, i.x, i.y), s = Model.elements[e].getShapeAngel(i), r = Utils.rotateCoordinate(t, i, 45), o = Math.atan((r.y - i.y) / (r.x - i.x)), a = o - s, Model.elements[e].calcuRotateAngel(-45, i.x, i.y), Model.elements[e].calcuRotateAngel(180 * a / Math.PI, i.x, i.y)) : (s = Model.elements[e].getShapeAngel(i), o = Math.atan((t.y - i.y) / (t.x - i.x)), a = o - s, Model.elements[e].calcuRotateAngel(180 * a / Math.PI, i.x, i.y)),
                        Designer.DisplayElements(n.children("canvas")[0]),
                        Designer.op.displayStatu(e, "selected")
                }
            },
            getShapeByPos: function (e) {
                for (var t = $("#designer_canvas"), n = 0; n < Model.elements.length; n++) if (Model.elements[n].inShape(t.children("canvas")[0], e)) return n;
                return -1
            },
            setControlPoint: function (e, t) {
                var n = $("#designer_canvas");
                -1 != e && Model.elements[e].setControlPoint(n.children("canvas")[0], t)
            },
            displayStatu: function (e, t) {
                if (-1 != e) {
                    var n = $("#designer_grids"),
                        o = $("#designer_canvas"),
                        a = n[0].getContext("2d");
                    if ("default" == t) Designer.DisplayElements(o.children("canvas")[0]);
                    else if ("selected" == t) {
                        a.save(),
                            a.strokeStyle = "blue",
                            a.fillStyle = "rgba(255,255,0,0.5)";
                        var s = Model.elements[e].getControlPoints();
                        if (0 != s) for (i = 0; i < s.length; i++) a.beginPath(),
                            a.arc(s[i].x, s[i].y, 5, 0, 2 * Math.PI, !1),
                            a.stroke(),
                            a.fill();
                        var r = Model.elements[e].getRotatePoint();
                        0 != r && (a.beginPath(), a.strokeStyle = "navy", a.fillStyle = "rgba(0, 255, 0, 0.5)", a.arc(r.x, r.y, 5, 0, 2 * Math.PI, !1), a.stroke(), a.fill()),
                            a.restore()
                    }
                }
            },
            removeElement: function () {
                var e = Designer.op.currentSelectedID;
                if (-1 != e) {
                    Designer.op.currentSelectedID = -1,
                        Model.deleteElement(e);
                    var t = $("#designer_canvas");
                    Designer.DisplayElements(t.children("canvas")[0])
                }
            },
            setSelectedStatu: function (e, t) {
                e ? Model.setSelected(t) : Model.cancelSelected()
            },
            moveLeft: function () {
                if (Designer.op.currentSelectedGroupID.length > 0) {
                    for (var e = 0; e < Designer.op.currentSelectedGroupID.length; e++) Model.moveShape(Designer.op.currentSelectedGroupID[e], -Designer.config.movePosPix, 0);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                var n = Designer.op.currentSelectedID;
                if (-1 != n) {
                    Model.moveShape(n, -Designer.config.movePosPix, 0);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                return !1
            },
            moveLeftShift: function () {
                if (Designer.op.currentSelectedGroupID.length > 0) {
                    for (var e = 0; e < Designer.op.currentSelectedGroupID.length; e++) Model.moveShape(Designer.op.currentSelectedGroupID[e], -Designer.config.moveSmallPosPix, 0);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                var n = Designer.op.currentSelectedID;
                if (-1 != n) {
                    Model.moveShape(n, -Designer.config.moveSmallPosPix, 0);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                return !1
            },
            moveRight: function () {
                if (Designer.op.currentSelectedGroupID.length > 0) {
                    for (var e = 0; e < Designer.op.currentSelectedGroupID.length; e++) Model.moveShape(Designer.op.currentSelectedGroupID[e], Designer.config.movePosPix, 0);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                var n = Designer.op.currentSelectedID;
                if (-1 != n) {
                    Model.moveShape(n, Designer.config.movePosPix, 0);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                return !1
            },
            moveRightShift: function () {
                if (Designer.op.currentSelectedGroupID.length > 0) {
                    for (var e = 0; e < Designer.op.currentSelectedGroupID.length; e++) Model.moveShape(Designer.op.currentSelectedGroupID[e], Designer.config.moveSmallPosPix, 0);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                var n = Designer.op.currentSelectedID;
                if (-1 != n) {
                    Model.moveShape(n, Designer.config.moveSmallPosPix, 0);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                return !1
            },
            moveUP: function () {
                if (Designer.op.currentSelectedGroupID.length > 0) {
                    for (var e = 0; e < Designer.op.currentSelectedGroupID.length; e++) Model.moveShape(Designer.op.currentSelectedGroupID[e], 0, -Designer.config.movePosPix);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                var n = Designer.op.currentSelectedID;
                if (-1 != n) {
                    Model.moveShape(n, 0, -Designer.config.movePosPix);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                return !1
            },
            moveUPShift: function () {
                if (Designer.op.currentSelectedGroupID.length > 0) {
                    for (var e = 0; e < Designer.op.currentSelectedGroupID.length; e++) Model.moveShape(Designer.op.currentSelectedGroupID[e], 0, -Designer.config.moveSmallPosPix);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                var n = Designer.op.currentSelectedID;
                if (-1 != n) {
                    Model.moveShape(n, 0, -Designer.config.moveSmallPosPix);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                return !1
            },
            moveDown: function () {
                if (Designer.op.currentSelectedGroupID.length > 0) {
                    for (var e = 0; e < Designer.op.currentSelectedGroupID.length; e++) Model.moveShape(Designer.op.currentSelectedGroupID[e], 0, Designer.config.movePosPix);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                var n = Designer.op.currentSelectedID;
                if (-1 != n) {
                    Model.moveShape(n, 0, Designer.config.movePosPix);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                return !1
            },
            moveDownShift: function () {
                if (Designer.op.currentSelectedGroupID.length > 0) {
                    for (var e = 0; e < Designer.op.currentSelectedGroupID.length; e++) Model.moveShape(Designer.op.currentSelectedGroupID[e], 0, Designer.config.moveSmallPosPix);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                var n = Designer.op.currentSelectedID;
                if (-1 != n) {
                    Model.moveShape(n, 0, Designer.config.moveSmallPosPix);
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                return !1
            },
            cancelSelected: function () {
                var e = Designer.op.currentSelectedID;
                if (-1 != e) {
                    Model.cancelSelected(),
                        Designer.op.currentSelectedID = -1;
                    var t = $("#designer_canvas");
                    return Designer.DisplayElements(t.children("canvas")[0]),
                        !0
                }
                return !1
            },
            copyGrp: !1,
            copyElement: function () {
                if (!(Designer.op.currentSelectedGroupID.length > 0)) {
                    var e = Designer.op.currentSelectedID;
                    return -1 != e ? (Designer.op.copyShapeIndex = Designer.op.currentSelectedID, !0) : !1
                }
                Designer.op.copyGrp = !0
            },
            pasetElement: function () {
                if (Designer.op.copyGrp) {
                    Designer.op.copyGrp = !1,
                        Designer.op.copyShapeIndex = -1;
                    for (var e = [], t = 0; t < Designer.op.currentSelectedGroupID.length; t++) {
                        var n = Designer.op.currentSelectedGroupID[t];
                        if (-1 != n && n >= 0 && n < Model.elements.length) {
                            var i = Utils.copy(Model.elements[n]),
                                o = Utils.newId();
                            i.id = o,
                                i.name = "",
                                i.nameText = "",
                                i.selected = !0,
                                Model.elements[n].selected = !1,
                                i.MoveOffset(30, 30),
                                Model.elements.push(i),
                                e.push(i),
                                Designer.op.currentSelectedGroupID[t] = Model.elements.length - 1
                        }
                    }
                    var a = $("#designer_canvas");
                    Designer.DisplayElements(a.children("canvas")[0])
                } else {
                    var n = Designer.op.copyShapeIndex;
                    if (-1 == n) return !1;
                    if (n >= 0 && n < Model.elements.length) {
                        var i = Utils.copy(Model.elements[n]),
                            o = Utils.newId();
                        i.id = o,
                            i.name = "",
                            i.nameText = "",
                            i.selected = !0,
                            Model.elements[n].selected = !1,
                            i.MoveOffset(30, 30),
                            Model.elements.push(i),
                            Designer.op.copyShapeIndex = Model.elements.length - 1;
                        var a = $("#designer_canvas");
                        return Designer.DisplayElements(a.children("canvas")[0]),
                            !0
                    }
                }
            },
            zoomCanvas: function (e) {
                if (e) {
                    var t = Designer.op.zoomCount;
                    if (Designer.op.zoomCount < .5) return;
                    Designer.op.zoomCount -= .1,
                        Designer.config.scale = Designer.op.zoomCount / t,
                        Designer.initialize.initCanvas();
                    var i = ($("#designer_grids"), $("#designer_canvas"));
                    Model.zoomShape(Designer.config.scale),
                        Designer.DisplayElements(i.children("canvas")[0])
                } else {
                    var t = Designer.op.zoomCount;
                    if (Designer.op.zoomCount >= 2) return void(Designer.op.zoomCount = 2);
                    Designer.op.zoomCount += .1,
                        Designer.config.scale = Designer.op.zoomCount / t,
                        Designer.initialize.initCanvas();
                    var i = ($("#designer_grids"), $("#designer_canvas"));
                    Model.zoomShape(Designer.config.scale),
                        Designer.DisplayElements(i.children("canvas")[0])
                }
            },
            scratShape: function () {
                Model.elements;
                if (1 != Designer.op.zoomCount) {
                    var t = 1 / Designer.op.zoomCount;
                    Designer.initialize.initCanvas();
                    var i = ($("#designer_grids"), $("#designer_canvas"));
                    Model.zoomShape(t),
                        Designer.DisplayElements(i.children("canvas")[0]),
                        Designer.op.zoomCount = 1
                }
            },
            saveThumbimg: function (e) {
                Designer.op.scratShape(),
                    UI.preViewPanel(!1);
                var t = document.getElementById("preView_canvas"),
                    n = t.toDataURL("image/jpeg", .3).replace(/^data:image\/\w+;base64,/, "");
                $.ajax({
                    url: "saveThumbimg",
                    data: {
                        id: Designer.stationID,
                        pngData: n
                    },
                    type: "post",
                    cache: !1,
                    dataType: "json",
                    success: function (e) {
                        e || 501 !== e ? cb(null, e) : cb("data error", null)
                    },
                    error: function () {
                        return document.location.href = encodeURI("./errorpage")
                    }
                })
            },
            saveStationFile: function (e, t) {
            }
        },
        hotkey: {
            init: function () {
                $(document).unbind("keydown.hotkey").bind("keydown.hotkey",
                    function (e) {
                        if (46 == e.keyCode || 8 == e.keyCode) Designer.op.removeElement() && e.preventDefault();
                        else if (e.shiftKey && 39 == e.keyCode) Designer.op.moveRightShift() && e.preventDefault();
                        else if (39 == e.keyCode) Designer.op.moveRight() && e.preventDefault();
                        else if (e.shiftKey && 37 == e.keyCode) Designer.op.moveLeftShift() && e.preventDefault();
                        else if (37 == e.keyCode) Designer.op.moveLeft() && e.preventDefault();
                        else if (e.shiftKey && 38 == e.keyCode) Designer.op.moveUPShift() && e.preventDefault();
                        else if (38 == e.keyCode) Designer.op.moveUP() && e.preventDefault();
                        else if (e.shiftKey && 40 == e.keyCode) Designer.op.moveDownShift() && e.preventDefault();
                        else if (40 == e.keyCode) Designer.op.moveDown() && e.preventDefault();
                        else if (e.ctrlKey && 188 == e.keyCode) Designer.op.zoomCanvas(!0),
                            e.preventDefault();
                        else if (e.ctrlKey && 190 == e.keyCode) Designer.op.zoomCanvas(!1),
                            e.preventDefault();
                        else if (27 == e.keyCode) Designer.op.cancelSelected() && e.preventDefault();
                        else if (e.ctrlKey && 67 == e.keyCode) Designer.op.copyElement() && e.preventDefault();
                        else if (e.ctrlKey && 86 == e.keyCode) Designer.op.pasetElement() && e.preventDefault();
                        else if (17 == e.keyCode) Designer.moveCanvas(),
                            e.preventDefault();
                        else if (e.ctrlKey && 83 == e.keyCode) e.preventDefault(),
                        Designer.initialize.initialized && (UI.isSaving || (UI.isSaving = !0, Designer.op.saveThumbimg(Model.StationImgPath), Designer.op.saveStationFile(Model.stationFilePath,
                            function () {
                                UI.isSaving = !1
                            })));
                        else if (e.ctrlKey && 66 == e.keyCode) {
                            new jFile;
                            e.preventDefault()
                        } else e.ctrlKey && 65 == e.keyCode && (Designer.selecteAll(), e.preventDefault())
                    })
            }
        },
        DrawGrid: function () {
            var e = Model.page.width,
                t = Model.page.height,
                n = Model.page.backgroundColor,
                i = Model.page.padding,
                o = "242,242,242",
                a = "229,229,229",
                s = $("#designer_grids"),
                r = s[0].getContext("2d");
            r.save(),
                r.clearRect(0, 0, e, t);
            var h = e,
                l = t;
            r.fillStyle = "rgb(" + n + ")",
                r.beginPath(),
                r.rect(i, i, h, l),
                r.fill();
            var c = Math.round(Model.page.gridSize);
            if (10 > c && (c = 10), Model.page.showGrid) {
                r.translate(i, i),
                    r.lineWidth = 1;
                for (var p = .5,
                         f = 0; l > p;) f % 4 == 0 ? r.strokeStyle = "rgb(" + a + ")" : r.strokeStyle = "rgb(" + o + ")",
                    r.beginPath(),
                    r.moveTo(0, p),
                    r.lineTo(h, p),
                    p += c,
                    f++,
                    r.stroke();
                for (p = .5, f = 0; h >= p;) f % 4 == 0 ? r.strokeStyle = "rgb(" + a + ")" : r.strokeStyle = "rgb(" + o + ")",
                    r.beginPath(),
                    r.moveTo(p, 0),
                    r.lineTo(p, l),
                    p += c,
                    f++,
                    r.stroke()
            }
            r.restore()
        },
        MoveItem: function (e, t, n, i) {
            for (var o = 0; o < Model.elements.length; o++) Model.elements[o].id == t.id && Model.elements[o].MoveOffset(n, i);
            this.DisplayElements(e)
        },
        selecteAll: function () {
            var e = $("#designer_grids");
            Designer.op.currentSelectedGroupID.splice(0, Designer.op.currentSelectedGroupID.length);
            for (var t = 0; t < Model.elements.length; t++) Designer.op.currentSelectedGroupID[t] = t,
                Designer.op.setSelectedStatu(!0, t);
            this.DisplayElements(e[0])
        },
        DisplayElements: function (e) {
            var t = e.getContext("2d");
            t.clearRect(0, 0, e.width, e.height);
            for (var n = 0; n < Model.elements.length; n++)("JYJ" !== Model.elements[n].category || Designer.op.jyjShowFlag) && ("BUTTON" !== Model.elements[n].category || Designer.op.buttonShowFlag || "BGBUTTON" === Model.elements[n].buttonType || "YXBUTTON" === Model.elements[n].buttonType) && Model.elements[n].showShape(e)
        },
        canvasDragTimeout: null,
        moveCanvas: function () {
            var e = $("#canvas_container");
            this.canvasDragTimeout && clearTimeout(this.canvasDragTimeout),
                this.canvasDragTimeout = setTimeout(function () {
                        e.unbind("mousemove.drag_canvas"),
                            $(document).unbind("mouseup.drag_canvas")
                    },
                    500),
                e.unbind("mousedown.drag_canvas").bind("mousedown.drag_canvas",
                    function (t) {
                        var n = $("#designer_layout").scrollTop(),
                            i = $("#designer_layout").scrollLeft();
                        e.bind("mousemove.drag_canvas",
                            function (e) {
                                if (e.ctrlKey) {
                                    var o = e.pageX - t.pageX,
                                        a = e.pageY - t.pageY;
                                    $("#designer_layout").scrollLeft(i - o),
                                        $("#designer_layout").scrollTop(n - a)
                                }
                            }),
                            $(document).unbind("mouseup.drag_canvas").bind("mouseup.drag_canvas",
                                function (t) {
                                    e.unbind("mousemove.drag_canvas"),
                                        $(document).unbind("mouseup.drag_canvas")
                                })
                    }),
                $(document).unbind("keyup.drag_canvas").bind("keyup.drag_canvas",
                    function (t) {
                        $(document).unbind("mouseup.drag_canvas"),
                            clearTimeout(this.canvasDragTimeout),
                            e.unbind("mousemove.drag_canvas"),
                            e.unbind("mousedown.drag_canvas")
                    })
        }
    },
    Utils = {
        getRelativePos: function (e, t, n) {
            var i = n.offset();
            return null == i && (i = {
                left: 0,
                top: 0
            }),
                {
                    x: e - i.left + n.scrollLeft(),
                    y: t - i.top + n.scrollTop()
                }
        },
        newId: function () {
            var e = Math.random(),
                t = e + (new Date).getTime();
            return t.toString(16).replace(".", "")
        },
        copy: function (e) {
            return $.extend(!0, {},
                e)
        },
        getLinePoint: function (e, t, n) {
            var i, o, a = {
                x: 0,
                y: 0
            };
            Math.abs(n.x - t.x) < .01 ? (i = 0, o = t.y) : (i = (n.y - t.y) / (n.x - t.x), o = t.y - i * t.x);
            var s = e,
                r = i * e + o;
            return a.x = s,
                a.y = r,
                a
        },
        rotateCoordinate: function (e, t, n) {
            var i, o, a, s, r = {
                x: 0,
                y: 0
            };
            return i = e.x,
                o = e.y,
                a = t.x,
                s = t.y,
                r.x = Math.cos(n * Math.PI / 180) * (i - a) - Math.sin(n * Math.PI / 180) * (o - s) + a,
                r.y = Math.cos(n * Math.PI / 180) * (o - s) + Math.sin(n * Math.PI / 180) * (i - a) + s,
                r
        },
        calcuAngel: function (e, t) {
            return Math.abs(e.x - t.x) < .01 ? Math.PI / 2 : Math.abs(e.y - t.y) < .01 ? 0 : Math.atan((e.y - t.y) / (e.x - t.x))
        },
        inPoint: function (e, t, n) {
            var i = e.getContext("2d"),
                o = t;
            return i.beginPath(),
                i.arc(o.x, o.y, 8, 0, 2 * Math.PI, !1),
                i.isPointInPath(n.x, n.y) ? !0 : !1
        }
    };
Number.prototype.toScale = function () {
    return this * Designer.config.scale
};